<template>
  <div class="home-singer">
    <h1>热门歌手</h1>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="cover">
            <van-image :src="item.singer_pic" radius="10" />
          </div>
          <span>{{ item.singer_name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
  data() {
    return {
      listData: [],
      pageNo: 1,
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData(singer_pic, singer_name) {
      this.$request("get", "/singer/list", {
        singer_pic,
        singer_name,
      }).then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.listData = res.data.list;
        }
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        );
      });
    },
    selectItem(item) {
      const id = item.singer_mid;
      console.log(id);
      // this.$store.commit('savaSinger',item)
      this.$store.dispatch('saveSingerAction',item);
      this.$router.push({
          path:`/singerhome/${id}`
      });
    },
  },
  //             )
  //             this.betterScrollHorizontal(this.listData.length, 10);
  //           })
  //     },
  //     betterScrollHorizontal(num, itemWidth){
  //         this.$refs.content.style.width = num * itemWidth + "rem"
  //             this.$nextTick(() => {
  //             this.scroll = new BScroll(this.$refs.wrapper, {
  //                 startX:0,
  //                 scrollX:true,
  //                 scrollY:false,
  //                 })
  //             })
  //     }
  // },
  // filters:{
  //     numFilter(value,num){
  //         return parseFloat(value/10000).toFixed(num)
  //     }
  // }
};
</script>
<style scoped>
/* .home-recommond>ul{ 
    display: flex;
     flex-wrap: wrap;
    }
.home-recommond>ul>li{

width:calc((100%- 1rem)/3*1);
}
.home-recommond>ul>li:nth-of-type(3n+2){
margin-left:0.5rem; 
margin-right: 0.5rem;
}*/
.cover {
  position: relative;
}
.cover > span {
  position: absolute;
  right: 0;
  bottom: 0.4rem;
  background-color: red;
  color: white;
  /* font-size: 14px; */
  border-radius: 1rem;
  width: 5rem;
  /* display:inline-block; */
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
/* ul.content{
    width: calc(12 * 10rem);
} */
ul.content > li {
  display: inline-block;
  width: 10rem;
  vertical-align: top;
}
ul.content > li * {
  margin: 0 0.1rem;
}
ul.content > li > span {
  font-size: 0.8rem;
  color: #54493b;
}
</style>